package com.ewhale.feitengguest.ui.shop.mine

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import com.ewhale.feitengguest.R
import com.ewhale.feitengguest.dto.ShopBillDetailDto
import com.ewhale.feitengguest.dto.ShopBillDto
import com.ewhale.feitengguest.dto.ShopWalletDto
import com.ewhale.feitengguest.presenter.shop.mine.ShopWalletPresenter
import com.ewhale.feitengguest.view.shop.mine.ShopWalletView
import com.simga.library.activity.MBaseActivity
import kotlinx.android.synthetic.main.activity_shop_wallet.*

class ShopWalletActivity : MBaseActivity<ShopWalletPresenter>(), ShopWalletView {
    override fun showShopBillList(list: List<ShopBillDto>) {}
    override fun showShopBillDetail(detatil: ShopBillDetailDto){}
    override fun isUseBaseTitleBar(): Boolean {return false}
    override fun getViewId(): Int {return R.layout.activity_shop_wallet}

    override fun init(savedInstanceState: Bundle?) {
        presenter.getShopWallet()
    }
    override fun showWallet(shopWalletDto: ShopWalletDto) {
        tv_balance.text = shopWalletDto.balance.stripTrailingZeros().toPlainString()
    }

    override fun initListener() {
        super.initListener()
        iv_back.setOnClickListener {
            finish()
        }
        btn_bill.setOnClickListener {
            ShopBillActivity.open(mContext)
        }
        tv_recharge.setOnClickListener {
            ShopRechargeActivity.open(mContext)
        }
        cl_draw.setOnClickListener {
            ShopWithDrawActivity.open(mContext,tv_balance.text.toString().toBigDecimal())
        }
    }

    override fun showProLoading() {
        showLoading()
    }

    override fun dimissProLoading() {
        dismissLoading()
    }

    override fun showErrorMessage(postCode: Int, code: String?, message: String?) {
        showErrorMsg(code, message)
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if(resultCode != Activity.RESULT_OK)return
        if(requestCode == 10001){
            presenter.getShopWallet()
        }
    }

    companion object {
        fun open(mContext: MBaseActivity<*>) {
            mContext.startActivity(null, ShopWalletActivity::class.java)
        }
    }
}
